package cn.dengqiang.order.controller;

import cn.dengqiang.basic.util.AjaxResult;
import cn.dengqiang.basic.util.LoginContext;
import cn.dengqiang.basic.util.PageList;
import cn.dengqiang.order.domain.AdoptOrder;
import cn.dengqiang.order.domain.OrderAddress;
import cn.dengqiang.order.query.AdoptOrderQuery;
import cn.dengqiang.order.service.IAdoptOrderService;
import cn.dengqiang.order.service.IOrderAddressService;
import cn.dengqiang.user.domain.LoginInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/petOrder")
public class PetOrderController {
    @Autowired
    private IAdoptOrderService orderService;

    @Autowired
    private IOrderAddressService orderAddressService;

    @PostMapping("/submit")
    public AjaxResult submit(@RequestBody Map<String,Object> params, HttpServletRequest request){

        try{
            String payData = orderService.submit(params, LoginContext.getLoginInfo(request));
            System.out.println(payData);
            return AjaxResult.me().setResultObj(payData);
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("下单失败！"+e.getMessage());
        }

    }


    @PostMapping("/admin")
    public PageList<AdoptOrder> queryAdminOrder(@RequestBody AdoptOrderQuery query, HttpServletRequest request){
        LoginInfo loginInfo = LoginContext.getLoginInfo(request);
        return  orderService.queryAdminOrder(query,loginInfo);

    }


    //用户查询接口
    @PostMapping("/user")
    public PageList<AdoptOrder> queryUserOrder(@RequestBody AdoptOrderQuery query,HttpServletRequest request){
        LoginInfo loginInfo = LoginContext.getLoginInfo(request);
        return  orderService.queryUserOrder(query,loginInfo);

    }




}
